/*****************************************************************************//*!
    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
    All rights reserved
*****************************************************************************/

/*----------------------------------------------------------------------------*/
#include <stdio.h>

/*----------------------------------------------------------------------------*/
#include "osObjects.h"
#include "systimer.h"

/*----------------------------------------------------------------------------*/
void PortInit(void);

/*----------------------------------------------------------------------------*/

int main( void )
{
    
    PortInit();
    
    SystemCoreClockUpdate();
    
    AppTaskCreate();
    
    AppObjCreate();
    
    /* Start the scheduler. */
	vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle
    task.  The idle task is created within vTaskStartScheduler(). */
	for( ;; );
}

/*****************************************************************************//*!
* @brief   	port init.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void PortInit()
{
    rcu_periph_clock_enable(RCU_GPIOA);
    rcu_periph_reset_enable(RCU_GPIOARST);
    rcu_periph_reset_disable(RCU_GPIOARST);
    
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_reset_enable(RCU_GPIOBRST);
    rcu_periph_reset_disable(RCU_GPIOBRST);
    
    rcu_periph_clock_enable(RCU_GPIOC);
    rcu_periph_reset_enable(RCU_GPIOCRST);
    rcu_periph_reset_disable(RCU_GPIOCRST);
    
    rcu_periph_clock_enable(RCU_GPIOD);
    rcu_periph_reset_enable(RCU_GPIODRST);
    rcu_periph_reset_disable(RCU_GPIODRST);
    
    rcu_periph_clock_enable(RCU_GPIOE);
    rcu_periph_reset_enable(RCU_GPIOERST);
    rcu_periph_reset_disable(RCU_GPIOERST);
    
    rcu_periph_clock_enable(RCU_GPIOF);
    rcu_periph_reset_enable(RCU_GPIOFRST);
    rcu_periph_reset_disable(RCU_GPIOFRST);
    
    rcu_periph_clock_enable(RCU_GPIOG);
    rcu_periph_reset_enable(RCU_GPIOGRST);
    rcu_periph_reset_disable(RCU_GPIOGRST);
    
    rcu_periph_clock_enable(RCU_GPIOH);
    rcu_periph_reset_enable(RCU_GPIOHRST);
    rcu_periph_reset_disable(RCU_GPIOHRST);
    
    rcu_periph_clock_enable(RCU_GPIOI);
    rcu_periph_reset_enable(RCU_GPIOIRST);
    rcu_periph_reset_disable(RCU_GPIOIRST);
    
    //LED
    gpio_mode_set(GPIOB,GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_3 | GPIO_PIN_4);
    gpio_output_options_set(GPIOB,GPIO_OTYPE_PP,GPIO_OSPEED_2MHZ,GPIO_PIN_3 | GPIO_PIN_4);
    //LED
    gpio_mode_set(GPIOD,GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7);
    gpio_output_options_set(GPIOD,GPIO_OTYPE_PP,GPIO_OSPEED_2MHZ,GPIO_PIN_7);
    //KEY
    gpio_mode_set(GPIOA,GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
    gpio_output_options_set(GPIOA,GPIO_OTYPE_PP,GPIO_OSPEED_2MHZ,GPIO_PIN_0);
    gpio_mode_set(GPIOE,GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_1);
    gpio_output_options_set(GPIOE,GPIO_OTYPE_PP,GPIO_OSPEED_2MHZ,GPIO_PIN_0 | GPIO_PIN_1);

}

/*****************************************************************************//*!
* @brief   	data init.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void DataInit(void){
  
}


/*****************************************************************************//*!
*
* @brief   Tick hook.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void vApplicationTickHook()
{
    SysTickCnt++;
}